# 1. Basic Image
FROM php:7.2-fpm
# 官方版本默认安装扩展:
# Core, ctype, curl
# date, dom
# fileinfo, filter, ftp
# hash
# iconv
# json
# libxml
# mbstring, mysqlnd
# openssl
# pcre, PDO, pdo_sqlite, Phar, posix
# readline, Reflection, session, SimpleXML, sodium, SPL, sqlite3, standard
# tokenizer
# xml, xmlreader, xmlwriter
# zlib

# 2. Environments
ENV TIME_ZONE            Asia/Shanghai

# 3. set timezone
RUN ln -sf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && echo $TIME_ZONE > /etc/timezone

# 4. set apt-get mirror
#RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list && rm -Rf /var/lib/apt/lists/* && apt-get update && cat /etc/apt/sources.list
RUN sed -i "s@http://deb.debian.org@http://mirrors.163.com@g" /etc/apt/sources.list && rm -Rf /var/lib/apt/lists/* && apt-get update && cat /etc/apt/sources.list

# 5. install php extension
RUN apt-get update --fix-missing && apt-get install -y  --no-install-recommends \
    libbz2-dev \
    libenchant-dev \
    libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
    libgmp-dev \
    libxml2-dev libtidy-dev libxslt1-dev \
    libzip-dev \
    libsnmp-dev \
    libpq-dev \
    libpspell-dev \
    librecode-dev \
    firebird-dev \
    freetds-dev \
    libldap2-dev \
    libc-client-dev libkrb5-dev \
    firebird-dev \
    libicu-dev \
    libmcrypt-dev \
    libmagickwand-dev libmagickcore-dev \
    librdkafka1 librdkafka-dev \
    && rm -r /var/lib/apt/lists/* \

    && docker-php-ext-install -j$(nproc) bcmath \
    && docker-php-ext-install -j$(nproc) calendar \
    && docker-php-ext-install -j$(nproc) exif \
    && docker-php-ext-install -j$(nproc) gettext \
    && docker-php-ext-install -j$(nproc) sockets \
    && docker-php-ext-install -j$(nproc) dba \
    && docker-php-ext-install -j$(nproc) mysqli \
    && docker-php-ext-install -j$(nproc) pcntl \
    && docker-php-ext-install -j$(nproc) pdo_mysql \
    && docker-php-ext-install -j$(nproc) shmop \
    && docker-php-ext-install -j$(nproc) sysvmsg \
    && docker-php-ext-install -j$(nproc) sysvsem \
    && docker-php-ext-install -j$(nproc) sysvshm \
    && docker-php-ext-install -j$(nproc) bz2 \
    && docker-php-ext-install -j$(nproc) enchant \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd \
    && docker-php-ext-install -j$(nproc) gmp \
    && docker-php-ext-install -j$(nproc) soap wddx xmlrpc tidy xsl\
    && docker-php-ext-install -j$(nproc) zip \
    && docker-php-ext-install -j$(nproc) snmp \
    && docker-php-ext-install -j$(nproc) pgsql pdo_pgsql \
    && docker-php-ext-install -j$(nproc) pspell \
    && docker-php-ext-install -j$(nproc) recode \
    && docker-php-ext-install -j$(nproc) pdo_firebird \
    && docker-php-ext-configure pdo_dblib --with-libdir=lib/x86_64-linux-gnu \
    && docker-php-ext-install -j$(nproc) pdo_dblib \
    && docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu \
    && docker-php-ext-install -j$(nproc) ldap \
    && docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
    && docker-php-ext-install -j$(nproc) imap \
    && docker-php-ext-install -j$(nproc) interbase \
    && docker-php-ext-install -j$(nproc) intl \
    && docker-php-ext-configure opcache --enable-opcache \
    && docker-php-ext-install opcache

RUN set -ex; \
    docker-php-source extract; \
    { \
         echo '# https://github.com/docker-library/php/issues/103#issuecomment-271413933'; \
         echo 'AC_DEFUN([PHP_ALWAYS_SHARED],[])dnl'; \
         echo; \
         cat /usr/src/php/ext/odbc/config.m4; \
    } > temp.m4; \
    mv temp.m4 /usr/src/php/ext/odbc/config.m4; \
    apt-get update; \
    apt-get install -y --no-install-recommends unixodbc-dev; \
    rm -rf /var/lib/apt/lists/*; \
    docker-php-ext-configure odbc --with-unixODBC=shared,/usr; \
    docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr; \
    docker-php-ext-install odbc pdo_odbc; \
    docker-php-source delete

# install php extension by pecl
RUN pecl install redis-5.0.0RC2 \
    && pecl install mcrypt-1.0.2 \
	&& pecl install xdebug-2.7.2 \
	&& pecl install imagick-3.4.4 \
	&& pecl install rdkafka-3.1.2 \
	&& docker-php-ext-enable mcrypt redis xdebug imagick rdkafka

# 6. install-Composer
RUN curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/local/bin/composer

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
COPY --chown=www:www . /var/www

WORKDIR /var/www/html
# Write Permission
RUN usermod -u 1000 www
USER www

# 7. set port and set up
EXPOSE 9000
CMD ["php-fpm"]

# 8. image Info.
LABEL Author="JustinLie"
LABEL Version="php-fpm7.2-v1"
LABEL Description="PHP FPM 7.2 镜像. All extensions."



